<template>
	<!-- 
	首页面
 -->
	<view class="centent">
		<!-- 自定义tabbar -->
		<u-tabbar style="z-index: 999" :value="value1" activeColor="#252525" inactiveColor="#c8c8c8" :fixed="true"
			:placeholder="false" :safeAreaInsetBottom="true">
			<u-tabbar-item text="首页" icon="home" @click="JumpComponent"></u-tabbar-item>
			<!-- <u-tabbar-item text="我的" icon="account" @click="JumpComponent"></u-tabbar-item> -->
		</u-tabbar>
		<!-- 首页 -->
		<MyHome v-if="infoList.length && value1===0" :infoList="infoList" />
		<!-- 我的 -->
		<Mine v-if="value1 == 1" />
	</view>
</template>


<script>
	import MyHome from "../index/myHome/myHome.vue";
	import Mine from "../index/mine/mine.vue";
	export default {
		components: {
			MyHome,
			Mine
		},
		data() {
			return {
				value1: 0,
				infoList: [],
				page: 1,
				pageSize:6,
			};
		},
		methods: {
			JumpComponent(e) {
				this.value1 = e;
			},
			async list(page,pageSize) {
				let {
					result
				} = await uniCloud.callFunction({
					name: 'consultList',
					data: {
						page,
						pageSize,
						consultState:0
					}
				});
				if(page === 1){
					this.infoList = result.data.data
				}else{
					result.data.data.forEach(element => {
						this.infoList.push(element)
					});
					
				}
			},
		},
		// // 滚动到底部加载数据
		onReachBottom() {
			this.list(this.page += 1,this.pageSize);
		},
		onPageScroll(e) {
			//根据距离顶部距离是否显示回到顶部按钮
			if (e.scrollTop > 500) {
				//当距离大于600时显示回到顶部按钮
				this.vm.$emit("customEvent", 1);
			} else {
				//当距离小于600时隐藏回到顶部按钮
				this.vm.$emit("customEvent", 0);
			}
		},
		onLoad() {
			this.list(this.page,this.pageSize)
			
			wx.showShareMenu({
				withShareTicket: true,
				//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus: ["shareAppMessage", "shareTimeline"],
			});
		},
		//发送给朋友
		onShareAppMessage(res) {
			// 此处的distSource为分享者的部分信息，需要传递给其他人
			let distSource = uni.getStorageSync("distSource");
			if (distSource) {
				return {
					title: "欢迎使用xxx商城",
					type: 0,
					path: "/pages/index/index?id=" + distSource,
					summary: "",
					imageUrl: "https://58d.oss-cn-hangzhou.aliyuncs.com/goods/ttg_1596073788000.png",
				};
			}
		},
		//分享到朋友圈
		onShareTimeline(res) {
			let distSource = uni.getStorageSync("distSource");
			if (distSource) {
				return {
					title: "欢迎使用xxx商城",
					type: 0,
					query: "id=" + distSource,
					summary: "",
					imageUrl: "https://58d.oss-cn-hangzhou.aliyuncs.com/goods/ttg_1596073788000.png",
				};
			}
		},
	};
</script>

<style lang="scss" scoped>
	.centent {
		/deep/ .u-icon__icon {
			span {
				font-size: 58rpx;
			}
		}
	}
</style>
